package org.example.design.composite;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.example.design.iterator.Iterator;

import java.util.ArrayList;

/**
 * @author huangshen
 * @version 0
 * @description Directory
 * @since 2022/2/8 23:22
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class Directory extends Entry {

    private String name;

    private ArrayList<Entry> directorys = new ArrayList<>();

    public Directory(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getSize() {
        int size = 0;
        for (Entry directory : directorys) {
            size += directory.getSize();
        }
        return size;
    }

    @Override
    public Entry add(Entry entry) {
        directorys.add(entry);
        return this;
    }

    @Override
    protected void printList(String prefix) {
        for (Entry directory : directorys) {
            directory.printList(prefix + "/" + name);
        }
    }
}
